//
//  JHUserPresenter.m
//  Demo_Pods
//
//  Created by gjh on 2021/3/8.
//  Copyright © 2021 gjh. All rights reserved.
//

#import "JHUserPresenter.h"
#import "JHUser.h"

@implementation JHUserViewData

- (instancetype)initWithName:(NSString *)name age:(NSString *)age {
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
    }
    return self;
}

@end

@implementation JHUserPresenter

- (void)getUsers {
    
    [JHUser getUsers:^(NSArray<JHUser *> * _Nonnull users) {
        
        // 判断user是否有值
        if (users && users.count) {
            NSMutableArray<JHUserViewData *> *datas = [NSMutableArray arrayWithCapacity:11];
            for (JHUser *user in users) {
                NSString *ageStr = [NSString stringWithFormat:@"年龄%ld", (long)user.age];
                
                JHUserViewData *viewData = [[JHUserViewData alloc] initWithName:user.firstName age:ageStr];
                
                [datas addObject:viewData];
            }
            // 代理回调
            if ([self.userViewDelegate respondsToSelector:@selector(setUser:)]) {
                [self.userViewDelegate setUser:datas];
            }
        }
    }];
}

@end
